package com.bdqn.controller;

import com.bdqn.pojo.SysUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

@Controller
public class SysUserController {
    @RequestMapping("/add")
    public String add(Map map, HttpServletRequest request) throws ParseException {
        String account = request.getParameter("account");
        String realName = request.getParameter("realName");
        String password = request.getParameter("password");
        String sex = request.getParameter("sex");
        String birthday = request.getParameter("birthday");
        String phone = request.getParameter("phone");
        String address = request.getParameter("address");
        DateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        Date s = f.parse(birthday);
        SysUser user = new SysUser(account,realName,password,Integer.valueOf(sex),s,phone,address);
        System.out.println("显示数据：" + user.toString());
        map.put("account",account);
        map.put("realName",realName);
        map.put("password",password);
        map.put("sex",sex);
        map.put("birthday",birthday);
        map.put("phone",phone);
        map.put("address",address);
        System.out.println("添加成功：" + map);
        return "add";
    }

    @RequestMapping("/toAdd")
    public String toAdd(){
        return "toadd";
    }
}
